<template>
  <div>
    <el-card>
      <el-form
        :inline="true"
        :model="query"
        label-width="100px"
        size="small"
      >
        <!-- 公司级别 -->
        <el-form-item class="query-form-item">
          <span>公司级别：</span>
          <el-select
            v-model="query.companylevel"
            placeholder="请选择公司级别"
            @change="onSubmit"
            clearable
          >
            <el-option
              label="全球公司"
              value="1"
            ></el-option>
            <el-option
              label="省级公司"
              value="2"
            ></el-option>
            <el-option
              label="市级公司"
              value="3"
            ></el-option>
            <el-option
              label="县级公司"
              value="4"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 公司类型 -->
        <el-form-item class="query-form-item">
          <span>公司类型：</span>
          <el-select
            v-model="query.companytype"
            placeholder="请选择公司类型"
            @change="onSubmit"
            clearable
          >
            <el-option
              label="孵化"
              value="0"
            ></el-option>
            <el-option
              label="临时"
              value="1"
            ></el-option>
            <el-option
              label="正式"
              value="2"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form
        :inline="true"
        :model="query"
        size="small"
      >
        <!-- 关键词检索 -->
        <el-form-item>
          <span> 公司名称：</span>
          <el-form-item class="query-form-item">
            <el-input
              v-model="query.companyname"
              placeholder="请输入公司名称"
              prefix-icon="el-icon-search"
              clearable
              style="magrin-left: 30px"
            ></el-input>
          </el-form-item>
        </el-form-item>
        <!-- 查询框 -->
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onRest"
          ></el-button>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="onSubmit"
          >搜索</el-button>
          <el-button
            type="primary"
            @click="add"
          >新增品牌公司</el-button>
          <el-button
            type="success"
            style="margin-left: 100px"
            @click="setRelationRecord"
          >品牌公司关系设置记录</el-button>
        </el-form-item>
      </el-form>
      <!-- table表单 -->
      <el-table
        ref="singleTable"
        :data="tableData"
        v-loading="loading"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
          width="50"
          fixed
        >
        </el-table-column>
        <el-table-column
          prop="companytype"
          align="center"
          label="公司类型"
          width="120"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.companytype == 0"
              style="color: #4acf1e"
            >孵化</span>
            <span
              v-else-if="scope.row.companytype == 1"
              style="color: #4acf1e"
            >临时</span>
            <span
              v-else-if="scope.row.companytype == 2"
              style="color: #4acf1e"
            >正式</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="companylevel"
          align="center"
          label="品牌公司级别"
          width="200"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.companylevel == 1"
              style="color: #4acf1e"
            >全球公司</span>
            <span
              v-else-if="scope.row.companylevel == 2"
              style="color: #4acf1e"
            >省级公司</span>
            <span
              v-else-if="scope.row.companylevel == 3"
              style="color: #4acf1e"
            >市级公司</span>
            <span
              v-else-if="scope.row.companylevel == 4"
              style="color: #4acf1e"
            >县级公司</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="companyid"
          align="center"
          :show-overflow-tooltip="true"
          label="品牌公司ID"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="companyname"
          align="center"
          :show-overflow-tooltip="true"
          label="品牌公司名称"
        ></el-table-column>
        <el-table-column
          prop="initiatingpartnerid"
          align="center"
          label="开发关系ID"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="initiatingpartnerlevel"
          align="center"
          :show-overflow-tooltip="true"
          label="开发关系公司级别"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.initiatingpartnerlevel == 1"
              style="color: #4acf1e"
            >全球公司</span>
            <span
              v-else-if="scope.row.initiatingpartnerlevel == 2"
              style="color: #4acf1e"
            >省级公司</span>
            <span
              v-else-if="scope.row.initiatingpartnerlevel == 3"
              style="color: #4acf1e"
            >市级公司</span>
            <span
              v-else-if="scope.row.initiatingpartnerlevel == 4"
              style="color: #4acf1e"
            >县级公司</span>
            <span
              v-else-if="scope.row.initiatingpartnername == '平台'"
              style="color: #4acf1e"
            >平台</span>
            <span v-else> 无</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="initiatingpartnername"
          align="center"
          :show-overflow-tooltip="true"
          label="开发关系公司名称"
        ></el-table-column>

        <el-table-column
          align="center"
          label="操作"
          width="120"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="editInfo(scope.$index, scope.row)"
            >设置</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination-container"
        background
        :page-size="query.pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :current-page="query.currentPage"
        :page-sizes="[5, 10, 20, 30, 50]"
        :total="totalNumber"
      ></el-pagination>
    </el-card>
  </div>
</template>
<script>
import { getWorkList } from '../../api/handWork/handWorkList'
export default {
  data() {
    return {
      tableData: [],
      query: {
        currentPage: 1,
        pageSize: 5,
        companylevel: '',
        companytype: '',
        companyname: '',
      },
      totalNumber: 0,
      loading: false,
    }
  },
  methods: {
    //搜索
    onSubmit() {
      this.query.currentPage = 1
      this.getList()
    },
    //刷新
    onRest() {
      this.query = {
        currentPage: 1,
        pageSize: 5,
        companylevel: '', //公司级别
        companytype: '', //公司类型
        companyname: '',
      }
      this.getList()
    },
    handleSizeChange(val) {
      this.query.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.query.currentPage = val
      this.getList()
    },
    //新增品牌公司
    add() {
      this.$router.push({ path: 'addCompany' })
    },
    //品牌公司关系设置
    setRelationRecord() {
      this.$router.push({ path: 'setRelationRecord' })
    },
    //设置更改信息
    editInfo(index, row) {
      this.$router.push({
        name: '公司信息编辑',
        query: { companyid: row.companyid },
      })
    },
    //获取品牌合伙公司列表
    getList() {
      this.loading = true
      getWorkList(this.query)
        .then((res) => {
          console.log(res)
          if (res.code != 0) {
            this.$message.error(res.message)
            this.loading = false
            return false
          }
          this.loading = false
          this.tableData = res.data.list
          this.totalNumber = res.data.totalNumber
        })
        .catch(() => {
          this.loading = false
          this.tableData = []
        })
    },
  },
  created() {
    this.getList() //获取列表
  },
}
</script>

